package com.ytjj.qmyx.admin.controller.supplyChain;

import com.ytjj.common.api.CommonPage;
import com.ytjj.common.api.CommonResult;
import com.ytjj.qmyx.admin.model.request.PayBillRequest;
import com.ytjj.qmyx.admin.model.response.PayBillResponse;
import com.ytjj.qmyx.admin.service.OrdersService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * 财务模块-交易账单
 */
@RestController
@RequestMapping("/payBill")
@RequiresPermissions("payBill:exportWxBill")
public class PayBillController {

    @Resource
    private OrdersService ordersService;

    /**
     * 导出账单
     */
    @PostMapping("/exportFundBill")
    public CommonResult exportFundBill(@RequestBody PayBillRequest request){
        ordersService.exportFundBill(request);
        return CommonResult.success();
    }

    /**
     * 获取支付宝下载信息
     */
    @GetMapping("/getAlipayBillDownload")
    public CommonResult getAlipayBillDownload(String timeDate,String billType){
        try {
            ordersService.alipayFunds(timeDate,billType);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return CommonResult.success();
    }

    /**
     * 分页查询交易账单列表
     */
    @PostMapping("/getBillListByPage")
    public CommonResult<CommonPage<PayBillResponse>> getBillListByPage(@RequestBody PayBillRequest request){
        CommonPage<PayBillResponse> billListByPage = ordersService.getBillListByPage(request);
        return CommonResult.success(billListByPage);
    }

    /**
     * 从列表下载交易账单
     * @param id 唯一id
     * @return
     */
    @GetMapping("/downloadBill")
    public void downloadBill(HttpServletResponse response, Integer id) {
        ordersService.downloadBill(response, id);
    }

    /**
     * 获取所有的支付账号信息
     */
    @GetMapping("/getAllPayAccount")
    public CommonResult getAllPayAccount() {
        Map<String, Object> allAccount = ordersService.getAllAccount();
        return CommonResult.success(allAccount);
    }

}
